/*
 * @Author: sbotlp
 * @Email: sbotlp@sina.com
 * @Date: 2019-06-29 17:44:54
 * @LastEditTime: 2019-06-30 10:30:43
 * @Description: http://www.sbotlp.com.cn
 */
import * as React from 'react';
import { Button, message } from 'antd';
import { connect } from 'src/app/redux/connect/Connect';
import { withRouter } from 'src/app/routers/WithRouter';
import { Card } from '../component/card/Card';
import { LoginService } from './Login.service';
import { useBullteAction, batchUseBullteAction } from 'src/app/redux/actions/Bullet.actions';
import './Login.scss';
interface Props extends React.Props<any> {
  history?: any
  Bullet?: any
  useBullteAction?: () => void
  batchUseBullteAction?: () => void
}
@withRouter
@connect(
  state => state,
  { useBullteAction, batchUseBullteAction }
)
export default class LoginComponent extends React.PureComponent<Props, any> {
  private service: LoginService;
  constructor(props: Props) {
    super(props);
    this.service = new LoginService();
  }
  goBack = () => {
    this.props.history.goBack();
  }
  use = () => {
    this.props.useBullteAction!();
  }
  batchUse = () => {
    this.props.batchUseBullteAction!();
  }
  testFecth = () => {
    this.service.notRes();
  }
  test2Fecth = () => {
    this.service.navigation({i: 123123, id12: 1111}).then(res => {
      console.log('res=>>>>>>>>>>>', res);
    }).catch(error => {
      console.log('error: ', error.err);
      message.error(error.err.id);
    })
  }
  testGetFecth = () => {
    this.service.testGet({cc: '消耗子弹', id1: 222}).then(res => {
      console.log('res: ', res);
    }).catch(error => {
      message.error(error.err.id);
      console.log('error: ', error.err);
    })
  }
  render() {
    return (
      <div className='login'>
        <Card title={<span className='title'>消耗子弹</span>}>消耗子弹</Card>
        <Card>
          <Button onClick={this.goBack}>去添加子弹</Button>
        </Card>
        <Card>
          <Button onClick={this.goBack}>
            当前子弹数量：{this.props.Bullet.bulletNumber}
          </Button>
        </Card>
        <Card>
          <Button type='danger' onClick={this.use}>
            使用子弹
          </Button>
        </Card>
        <Card>
          <Button type='danger' onClick={this.batchUse}>
            批量使用子弹
          </Button>
        </Card>
        <Card>
          <Button type='danger' onClick={this.testFecth}>
            测试请求超时
          </Button>
        </Card>
        <Card>
          <Button type='danger' onClick={this.test2Fecth}>
            测试正常请求
          </Button>
        </Card>
        <Card>
          <Button type='danger' onClick={this.testGetFecth}>
            传参测试get请求
          </Button>
        </Card>
      </div>
    )
  }
}
